package com.lkd.controller;


import com.lkd.entity.Node;
import com.lkd.service.NodeService;
import com.lkd.vo.NodeVo;
import com.lkd.vo.PageBean;
import com.lkd.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 点位表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-20
 */
@RestController
@RequestMapping("/api/vm-service/node")
public class NodeController {
    @Autowired
    private NodeService nodeService;


    @GetMapping("/search")
    public Result search(String regionId,String name,
                         @RequestParam(defaultValue = "1")Integer pageIndex,
                         @RequestParam(defaultValue = "10")Integer pageSize){
        PageBean<NodeVo>page=nodeService.search(regionId,name,pageIndex,pageSize);
        return Result.success(page);
    }

    //新增点位
    @PostMapping
    public Result save(@RequestBody Node node){
        nodeService.save(node);
        return Result.success();
    }

    //修改点位
    @PutMapping
    public Result update(@RequestBody Node node){
        nodeService.updateById(node);
        return Result.success();
    }

    //删除点位
    @DeleteMapping("/{nodeId}")
    public Result delete(@PathVariable Long nodeId){
        nodeService.removeById(nodeId);
        return Result.success();
    }

    //统计点位数量
    @GetMapping("/count")
    public Result count(){
        return Result.success(nodeService.count());
    }

}
